package com.zhyt.intelligentpipeline.controller;

import com.zhyt.intelligentpipeline.model.*;
import com.zhyt.intelligentpipeline.service.StationService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("station")
public class StationController {

    @Resource
    private StationService stationService;


    /***
     *
     * dfsfsdfds
     */

    @GetMapping("{station_name}")
    public Station getStationByName(@PathVariable(value = "station_name")String station_name){
        return stationService.getStationByName(station_name);
    }


    @GetMapping("{station_name}/time/{time}")
    public GasComponent getStationGasComponent(@PathVariable(value = "station_name")String station_name,

                                               @PathVariable(value = "time")String  time){
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date = sdf.parse(time);
            return stationService.getStationGasComponent(date,station_name);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    @GetMapping("{station_name}/time/{time}/supplyGas")
    public List<SupplyGas> getStationSupplyGasVolume(@PathVariable(value = "station_name")String station_name,
                                                     @PathVariable(value = "time")String  time){
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date = sdf.parse(time);
            return stationService.getStationSupplyGasVolume(date,station_name);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    @GetMapping("/intakeSite/{intakeSite}/time/{time}")
    public IntakeGas getStationIntakeGas(
                                         @PathVariable(value = "intakeSite")String  intakeSite,
                                         @PathVariable(value = "time")String time){
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date = sdf.parse(time);
            return stationService.getStationIntake(date,intakeSite);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }


    @GetMapping("/{stationName}/time/{time}/TransferPressure")
    public TransferPressure getStationPressure( @PathVariable(value = "stationName")String  stationName,
                                                @PathVariable(value = "time")String time){
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date = sdf.parse(time);
            return stationService.getStationTransPressure(date,stationName);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

}
